﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Urd.Packet
{
    public class XYZ
    {
        const byte size = 16;
        int id;
        float x, y, z;
        public XYZ(int id, float x, float y, float z)
        {
            this.id = id;
            this.x = x;
            this.y = y;
            this.z = z;
        }

        public XYZ(byte[] buf)
        {
            if (buf.Length < size)
            {
                id = 0;
                x = y = z = 0f;
            }
            else
            {
                //opcode = buf[0];
                //command = buf[1];
                //size = buf[2];
                id = BitConverter.ToInt32(buf, 0);
                x = BitConverter.ToSingle(buf, 4);
                y = BitConverter.ToSingle(buf, 8);
                z = BitConverter.ToSingle(buf, 12);
            }
        }
        public byte[] bytes
        {
            get
            {
                byte[] buf = new byte[size];
                Array.Copy(BitConverter.GetBytes(id), 0, buf, 0, 4);
                Array.Copy(BitConverter.GetBytes(x), 0, buf, 4, 4);
                Array.Copy(BitConverter.GetBytes(y), 0, buf, 8, 4);
                Array.Copy(BitConverter.GetBytes(z), 0, buf, 12, 4);
                return buf;
            }
        }
        public bool isEmpty
        {
            get
            {
                return (x == 0 && y == 0 && z == 0 && id == 0);
            }
        }
        public float X { get { return x; } }
        public float Y { get { return y; } }
        public float Z { get { return z; } }
        public int ID { get { return id; } }
    }
    public class XYZR
    {
        const byte size = 20;
        int id;
        float x, y, z, r;
        public XYZR(int id, float x, float y, float z,float r)
        {
            this.id = id;
            this.x = x;
            this.y = y;
            this.z = z;
            this.r = r;
        }

        public XYZR(byte[] buf)
        {
            if (buf.Length < size)
            {
                id = 0;
                x = y = z = r = 0f;
            }
            else
            {
                //opcode = buf[0];
                //command = buf[1];
                //size = buf[2];
                id = BitConverter.ToInt32(buf, 0);
                x = BitConverter.ToSingle(buf, 4);
                y = BitConverter.ToSingle(buf, 8);
                z = BitConverter.ToSingle(buf, 12);
                r = BitConverter.ToSingle(buf, 16);
            }
        }
        public byte[] bytes
        {
            get
            {
                byte[] buf = new byte[size];
                Array.Copy(BitConverter.GetBytes(id), 0, buf, 0, 4);
                Array.Copy(BitConverter.GetBytes(x), 0, buf, 4, 4);
                Array.Copy(BitConverter.GetBytes(y), 0, buf, 8, 4);
                Array.Copy(BitConverter.GetBytes(z), 0, buf, 12, 4);
                Array.Copy(BitConverter.GetBytes(r), 0, buf, 16, 4);
                return buf;
            }
        }
        public bool isEmpty
        {
            get
            {
                return (x == 0 && y == 0 && z == 0 && r ==0 && id == 0);
            }
        }
        public float X { get { return x; } }
        public float Y { get { return y; } }
        public float Z { get { return z; } }
        public float R { get { return r; } }
        public int ID { get { return id; } }
    }
    public class XYZRP
    {
        const byte size = 24;
        int id;
        float x, y, z, r, p;
        public XYZRP(int id, float x, float y, float z, float r,float p)
        {
            this.id = id;
            this.x = x;
            this.y = y;
            this.z = z;
            this.r = r;
            this.p=p;
        }

        public XYZRP(byte[] buf)
        {
            if (buf.Length < size)
            {
                id = 0;
                x = y = z = r = 0f;
            }
            else
            {
                //opcode = buf[0];
                //command = buf[1];
                //size = buf[2];
                id = BitConverter.ToInt32(buf, 0);
                x = BitConverter.ToSingle(buf, 4);
                y = BitConverter.ToSingle(buf, 8);
                z = BitConverter.ToSingle(buf, 12);
                r = BitConverter.ToSingle(buf, 16);
                p = BitConverter.ToSingle(buf, 20);
            }
        }
        public byte[] bytes
        {
            get
            {
                byte[] buf = new byte[size];
                Array.Copy(BitConverter.GetBytes(id), 0, buf, 0, 4);
                Array.Copy(BitConverter.GetBytes(x), 0, buf, 4, 4);
                Array.Copy(BitConverter.GetBytes(y), 0, buf, 8, 4);
                Array.Copy(BitConverter.GetBytes(z), 0, buf, 12, 4);
                Array.Copy(BitConverter.GetBytes(r), 0, buf, 16, 4);
                Array.Copy(BitConverter.GetBytes(p), 0, buf, 20, 4);
                return buf;
            }
        }
        public bool isEmpty
        {
            get
            {
                return (x == 0 && y == 0 && z == 0 && r == 0&& p==0 && id == 0);
            }
        }
        public float X { get { return x; } }
        public float Y { get { return y; } }
        public float Z { get { return z; } }
        public float R { get { return r; } }
        public float P { get { return p; } }
        public int ID { get { return id; } }
    }
}
